package com.yangwudi.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.yangwudi.mapper.StudentMapper;
import com.yangwudi.pojo.Emp;
import com.yangwudi.pojo.PageResult;
import com.yangwudi.pojo.Student;
import com.yangwudi.pojo.StudentQueryParam;
import com.yangwudi.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;


@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;
    @Override
    public PageResult<Student> page(StudentQueryParam studentQueryParam) {
        //1. 设置分页参数
        PageHelper.startPage(studentQueryParam.getPage(),studentQueryParam.getPageSize());

        //2. 执行查询
        List<Student> stuList = studentMapper.list(studentQueryParam);

        //3. 解析查询结果，并封装
        Page<Student> p = (Page<Student>) stuList;
        return new PageResult<Student>(p.getTotal(),p.getResult());
    }


    @Override
    public void deleteByIds(List<Integer> ids) {
        studentMapper.deleteByIds(ids);
    }

    @Override
    public void addStudent(Student student) {
        student.setCreateTime(LocalDateTime.now());
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.addStudent(student);
    }


    @Override
    public Student getById(Integer id) {
        return studentMapper.getById(id);
    }


    @Override
    public void update(Student student) {
        studentMapper.update(student);
    }

    @Override
    public void handleViolation(Integer id, Integer violationScore) {
        studentMapper.handleViolation(id,violationScore);
    }
}
